package com.xx.lm.webviewloadlocalimg;

import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;

/**
 * Created by apple on 18/1/31.
 */

//自定义的WebViewClient,重载shouldInterceptRequest方法
class MyWebViewClient extends WebViewClient {
    public MyWebViewClient(WebView webView) {
//        super(webView);
    }
    @Override
    public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
        String key = "http://localhost";
        final WebResourceResponse[] response = {null};
        if(url.contains(key)){
            //拿到文件地址
            String imgPath = url.replace(key,"");
//            CacheEngine.getInstance().getLocalImgInMain(imgPath)
//                    .subscribe(new Action1<byte[]>() {
//                        @Override
//                        public void call(byte[] bytes) {
//                            response[0] = new WebResourceResponse("image/png", "UTF-8", new ByteArrayInputStream(bytes));
//                        }
//                    });
            return response[0];
        }else {
            return super.shouldInterceptRequest(view, url);
        }
    }
}

